<div id="maincontent">
	<div id="content">
    
    <h2><?php echo lico_lang('uptime', 'page.title'); ?></h2>
    
    <div class="box1">
      <?php
      include_once("libs/xml.class.php");
      $xml = file_get_contents("xml/kernel_overall_uptimes.xml");
      $domObj = new xmlToArrayParser($xml);
      $domArr = $domObj->array;
      $generated = $domArr['statistics']['_']['generated'];
      $gesamt = 0;
      for ($a=0; $a<count($domArr['statistics']['line']); $a++) {
        $gesamt += intval($domArr['statistics']['line'][$a]['uptime']);
      }
      
      $selc = "SELECT COUNT(m.`f_key`) AS mnum FROM machines m LEFT JOIN `users` u ON (u.`f_key`=m.`owner`) WHERE u.`state`=1 AND m.`publish_versions`='YES' AND m.`uptime`!='' AND m.`isactive`='YES' AND `kernel`!=''";
      $retc = $db->unbuffered_query_first($selc);
      $num_machines = $retc[0];
      
      $avg = round($gesamt / $num_machines);
      $avg_formatted = lico_GetDurationFormated($avg);
      
      $data = $domArr['statistics']['line'];
      $array = array();
      $ca = 0;
      for ($a=0; $a<count($data); $a++) {
        $array['kernel'][$ca] = $data[$a]['kernel'];
        $array['uptime'][$ca] = $data[$a]['uptime'];
        $array['uptime_formatted'][$ca] = $data[$a]['uptime_formatted'];
        $array['average'][$ca] = $data[$a]['average'];
        $array['average_formatted'][$ca] = $data[$a]['average_formatted'];
        $array['machines'][$ca] = $data[$a]['machines'];
        $ca++;
      }
      array_multisort($array['uptime'], SORT_NUMERIC, SORT_DESC,
                      $array['kernel'],
                      $array['uptime_formatted'],
                      $array['average'],
                      $array['average_formatted'],
                      $array['machines']);
      ?>
      <h3><?php echo lico_lang('uptime', 'uptime.page.title'); ?></h3>
        <div class="description"><?php echo str_replace("#num#", lico_GetDurationFormated($gesamt), lico_lang('uptime', 'uptime.page.description')); ?><br/><small>(Generated: <?php echo $generated; ?>)</small><br/><br/>
        <b><?php echo str_replace("#avg#", $avg_formatted." (".$num_machines." machines)", lico_lang('uptime', 'uptime.avg')); ?></b></div>
        <div class="infotable-line <?php echo $class; ?>">
          <ul class="infotable-ul">
            <li class="infotable-li col04"><span><strong>Major Kernel version</strong></span></li>
            <li class="infotable-li col11"><span><strong>Uptime of all machines</strong></span></li>
            <li class="infotable-li col11"><span><strong>Average uptime</strong></span></li>
            <li class="infotable-li col02"><span><strong>Machines</strong></span></li>
          </ul>
        </div>
      <?php
      for ($a=0; $a<count($array['kernel']); $a++) {
        if ($class == "odd") $class = "even"; else $class = "odd";
        ?>
        <div class="infotable-line <?php echo $class; ?>">
          <ul class="infotable-ul">
            <li class="infotable-li col04"><span><?php echo trim($array['kernel'][$a]); ?></span></li>
            <li class="infotable-li col11"><span><?php echo $array['uptime_formatted'][$a]; ?></span></li>
            <li class="infotable-li col11"><span><?php echo $array['average_formatted'][$a]; ?></span></li>
            <li class="infotable-li col02"><span><?php echo $array['machines'][$a]; ?></span></li>
          </ul>
        </div>
        <?php
      }
      ?>
      
    </div>
    
    
    
    
    
    
    
    <div class="box2">
      <?php
      include_once("libs/xml.class.php");
      $xml = file_get_contents("xml/kernel_version_uptimes.xml");
      $domObj = new xmlToArrayParser($xml);
      $domArr = $domObj->array;
      $generated = $domArr['statistics']['_']['generated'];
      
      $selc = "SELECT COUNT(m.`f_key`) AS mnum FROM machines m LEFT JOIN `users` u ON (u.`f_key`=m.`owner`) WHERE u.`state`=1 AND m.`publish_versions`='YES' AND m.`uptime`!='' AND m.`isactive`='YES' AND m.`uptime`!='' AND m.`kernel`!=''";
      $retc = $db->unbuffered_query_first($selc);
      $num_machines = $retc[0];
      
      $data = $domArr['statistics']['line'];
      $array = array();
      $ca = 0;
      for ($a=0; $a<count($data); $a++) {
        $array['kernel'][$ca] = $data[$a]['kernel'];
        $array['maxuptime'][$ca] = $data[$a]['maxuptime'];
        $array['maxuptime_formatted'][$ca] = $data[$a]['maxuptime_formatted'];
        $ca++;
      }
      array_multisort($array['maxuptime'], SORT_NUMERIC, SORT_DESC,
                      $array['kernel'],
                      $array['maxuptime_formatted']);
      ?>
      <h3><?php echo lico_lang('uptime', 'maxuptime.page.title'); ?></h3>
        <div class="description"><?php echo lico_lang('uptime', 'maxuptime.page.description'); ?><br/><small>(Generated: <?php echo $generated; ?>)</small><br/></div>
        <div class="infotable-line <?php echo $class; ?>">
          <ul class="infotable-ul">
            <li class="infotable-li col11"><span><strong>Kernel version</strong></span></li>
            <li class="infotable-li col16"><span><strong>Max. uptime of one single machine with this kernel version</strong></span></li>
          </ul>
        </div>
      <?php
      for ($a=0; $a<count($array['kernel']); $a++) {
        if ($class == "odd") $class = "even"; else $class = "odd";
        ?>
        <div class="infotable-line <?php echo $class; ?>">
          <ul class="infotable-ul">
            <li class="infotable-li col11"><span><?php echo trim($array['kernel'][$a]); ?></span></li>
            <li class="infotable-li col16"><span><?php echo $array['maxuptime_formatted'][$a]; ?></span></li>
          </ul>
        </div>
        <?php
      }
      ?>
      
    </div>
    
    
    
    
    
    
  </div>
</div>
